/*
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 *
 * Copyright @2008 the original author or authors.
 */
package com.bluestone.action;

import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;

import com.bluestone.BaseAction;
import com.bluestone.context.IContext;
import com.bluestone.scripts.ActionScript;
import com.bluestone.scripts.Attributes;
import com.bluestone.scripts.Browser;
import com.bluestone.scripts.Proxy;
import com.bluestone.util.Util;

/**
 * @author <a href="mailto:bluesotne.master@gmail.com">daniel.q</a>
 *
 */
public class CheckProjectAction extends BaseAction{
	
	/**
	 * @param type
	 */
	public CheckProjectAction(ActionScript action) {
		super(action);
		// TODO Auto-generated constructor stub
	}	


	
	public boolean execute(IContext context){
		if (!super.execute(context)){
			return false;
		}
		String target = action.getPara("target");
		if(Attributes.START.equalsIgnoreCase(target)){
			//start server
			ActionScript a = new ActionScript();
			a.setType(ActionFactory.STARTSERVERACTION);
			ActionFactory.createAction(a).execute(context);
			
			//set proxy in browser
			//ActionFactory.createAction(ActionFactory.SETPROXYACTION, null, null, null, null).execute();
			
			
			// cut project icon
			ActionScript b = new ActionScript();
			b.setType(ActionFactory.MAXPAGEACTION);
			ActionFactory.createAction(b).execute(context);
			BufferedImage image = robot.createScreenCapture(new Rectangle(5,5,100,10));
			//Util.getCurrentProject().setIcon(image);
			robot.delay(Util.getDelayTime(Util.DELAY300));
			
	        //check browser
			//ActionFactory.createAction(ActionFactory.CHECKBROWSERACTION, null, null, null, null).execute();
			
		}else if(Attributes.STOP.equalsIgnoreCase(target)){
			//stop server
			ActionScript a = new ActionScript();
			a.setType(ActionFactory.STOPSERVERACTION);
			ActionFactory.createAction(a).execute(context);
			
			//unset proxy in browser
			//ActionFactory.createAction(ActionFactory.UNSETPROXYACTION, null, null, null, null).execute();
			
		}
		return true;
	}

}

